//
//  GameDetailController.swift
//  d11
//
//  Created by rhonin on 2018/11/21.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit
import WebKit
class GameDetailController: GameRootViewController,WKNavigationDelegate {
    let wkweb = WKWebView()
    var content :String?
    var url : String?
    var titles = ""
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let topLogo = UIImage(named: "icon_nav_left_logo")
        let titleView = UIView()
        let topLogoView = UIImageView(image: topLogo)
        titleView.addSubview(topLogoView)
        topLogoView.contentMode = .scaleToFill
        topLogoView.frame = CGRect(x: -(137/2), y:-(35/2), width: 137, height: 35)
        navigationItem.titleView = titleView
      wkweb.navigationDelegate = self
       view.addSubview(wkweb)
        wkweb.snp.makeConstraints { (make) in
            make.edges.equalTo(UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0))
        }
        if content != nil {
            wkweb.loadHTMLString(content!, baseURL: nil)
        }
        if url != nil {
//           url = "https://www.cnblogs.com/liyingnan/p/5667264.html"
            wkweb.load( URLRequest(url: URL(string: url!)!) )
        }
        self.title = titles
        self.view.addSubview(self.loadingView)
    }
    
    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        self.loadingView.removeFromSuperview()
    }
    func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
          self.loadingView.removeFromSuperview()
    }
    func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
         self.loadingView.removeFromSuperview()
//        MBProgressHUD.showMessage("网络异常", to: view)
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
